
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

class Solution {
    List<List<Integer>> List=new ArrayList<>();
    public List<List<Integer>> threeSum(int[] nums) {
        Arrays.sort(nums);
        for (int i = 0; i < nums.length-2; i++) {
            if (i >= 1 && nums[i] == nums[i - 1]) {
                i++;
            }
            if (i < nums.length-2) {
                int cur = nums[i];
                find(-cur, i + 1, nums.length - 1, nums);

            }
        }
            return List;


    }
    public void find(int val, int left, int right, int[] nums){
        while(left<right){
            List<Integer> list=new ArrayList<>();
            if(nums[left]+nums[right]<val){
                left++;

            }else if(nums[left]+nums[right]>val){
                right--;
            }else{
                int left2=nums[left];
                int right2=nums[right];
                list.add(-val);
                list.add(nums[left]);
                list.add(nums[right]);
                List.add(list);
                while(left<right&&nums[left]==left2){
                    left++;
                }
                while(left<right&&nums[right]==right2){
                    right--;
                }



            }
        }

    }

}